package cn.udrm.water.base.v1.manager.repository;

import java.util.List;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import cn.udrm.water.base.v1.manager.entities.BaseOrganization;

@Repository
public interface BaseOrganizationRepository extends JpaRepository<BaseOrganization, String> {

	@Query(value="FROM BaseOrganization WHERE id=?1")
	@EntityGraph(value="BaseOrganization.departments", type=EntityGraphType.FETCH)
	public BaseOrganization findWithDepartmentsById(String id);
	
	@Query(value="FROM BaseOrganization")
	@EntityGraph(value="BaseOrganization.departments", type=EntityGraphType.FETCH)
	public List<BaseOrganization> findAllWithDepartments();
	
	@Query(value="FROM BaseOrganization WHERE id=?1")
	@EntityGraph(value="BaseOrganization.roles", type=EntityGraphType.FETCH)
	public BaseOrganization findWithRolesById(String id);
	
	@Query(value="FROM BaseOrganization")
	@EntityGraph(value="BaseOrganization.roles", type=EntityGraphType.FETCH)
	public List<BaseOrganization> findAllWithRoles();
	
	@Query(value="FROM BaseOrganization WHERE id=?1")
	@EntityGraph(value="BaseOrganization.all", type=EntityGraphType.FETCH)
	public BaseOrganization findAllById(String id);
	
	@Query(value="FROM BaseOrganization WHERE id=?1")
	public BaseOrganization get(String id);
	
	//cannot simultaneously fetch multiple bags
	/*@Query(value="FROM BaseOrganization")
	@EntityGraph(value="BaseOrganization.all", type=EntityGraphType.LOAD)
	public List<BaseOrganization> findAlls();*/
}
